﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interop;
using System.Threading;

namespace TTIServer.TTISettings
{
	/// <summary>
	/// Interaction logic for RotationMenu.xaml
	/// </summary>
	public partial class RotationMenu : Window
	{

		public delegate void AngleRenderCallback(float angle);

		float ang1=0, ang2=-1, ang3=-1, ang4=-1;
		float high=-1, low=-1;

		public bool HILO=false;

		public RotationMenu()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}

		public void setRotationAngle(float angle)
		{
			float avgAngle = 0;

			if (ang2 == -1)
			{
				ang2 = angle;
				ang3 = angle;
				ang4 = angle;
			}
			else
			{

				ang4 = ang3;
				ang3 = ang2;
				ang2 = ang1;
				ang1 = angle;



			}

			//avgAngle = (ang1 + ang2 + ang3 + ang4) / 4;
			this.Dispatcher.BeginInvoke(new AngleRenderCallback(rotateMain), new object[] { angle/10 });

		}


		public void rotateMain(float ang)
		{
			if (HILO == true)
				if (high == -1)
				{
					low = ang;
					high = ang;
				}
				else
				{
					low = ang < low ? ang : low;
					high = ang > high ? ang : high;
				}
			else
			{
				high = -1;
				low = -1;
			}



			label1.Content = (ang).ToString();
			label2.Content = (high.ToString());
			label3.Content = low.ToString();

			float newAng = (high + low) / 2;

			RotateTransform myRT = new RotateTransform(ang,MainCircle.Width/2,MainCircle.Height/2);
			MainCircle.RenderTransform = myRT;


		}


	}
}